import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NavigationDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => NavigationState();
}

class NavigationState extends State<NavigationDemo> {
  int _selectedIndex = 0;
  final _widgetOptions = <Widget>[
    Text('index 0:信息'),
    Text('index 1:通讯录'),
    Text('index 2:发现'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('BottomNavigationBar示例'),
        centerTitle: true,
        //导航栏右侧菜单
        actions: <Widget>[
          IconButton(
              onPressed: () {
                print('分享');
              },
              icon: Icon(Icons.share))
        ],
      ),
      body: Center(
        child: _widgetOptions[_selectedIndex],
      ),
      //底部导航栏
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selectedIndex,
        fixedColor: Theme.of(context).accentColor,
        onTap: (index) {
          setState(() {
            _selectedIndex = index;
          });
        },
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.message), label: '信息'),
          BottomNavigationBarItem(
              icon:Icon(Icons.perm_contact_calendar), label: '通讯录'),
          BottomNavigationBarItem(icon: Icon(Icons.account_circle), label: '发现')
        ],
      ),
      //悬浮按钮
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: ()=>null,
      ),
    );
  }
}
